package com.qixin.web.controller.System;

import com.qixin.util.weixin.CheckWeChatToken;
import com.qixin.util.weixin.SHA1;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;

/**
 * Created by Zhang on 2018/10/1.
 *
 */
@Controller
@RequestMapping("/checkWechat")
public class checkWechatHttpController {

    //验证微信TOKEN
    @RequestMapping("/check")
    public void check(String signature, String timestamp, String nonce, String echostr, HttpServletRequest request, HttpServletResponse response) {
         //字典排序 和 加密 后的token和微信服务器的token是否一样
        if(CheckWeChatToken.checkSignature(signature,timestamp,nonce)){
            try {
                response.getWriter().print(echostr);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }


}
